var __holder = null;
var __event_fixed = false;
var __rte_editors = [];
var CK_EDITOR_TOOLBAR = [
    ['Styles','Format','Font','FontSize', '-', 'TextColor','BGColor'],
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    ['Undo', 'Redo', '-', 'Copy', 'Cut', 'Paste', '-', 'PasteText','PasteFromWord', '-', 'SelectAll', 'RemoveFormat'],
    ['Preview', '-', 'Maximize', 'ShowBlocks'], '/',

    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    ['Link','Unlink','Anchor'],
    ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak']
];

function _browseServer () {
    var event = window.event || arguments [0];

    if (!__event_fixed) {
        FixPrototypeForGecko ();
        __event_fixed = true;
    }

    event.cancelBubble = true;
//    if (!__holder) {
        var dialog = this._.dialog;
        var txtURL = dialog.getContentElement('info', 'txtUrl').getInputElement().$.id;
        var txtWidth = dialog.getContentElement('info', 'txtWidth').getInputElement().$.id;
        var txtHeight = dialog.getContentElement('info', 'txtHeight').getInputElement().$.id;
        var txtAlt = dialog.getContentElement ('info', 'txtAlt').getInputElement().$.id;
        __holder = {url : txtURL, width: txtWidth, height: txtHeight, contorl: dialog.getContentElement('info', 'txtUrl'), alt:txtAlt};
//    }
    var url = CONTEXT_PATH + '/browser/browser.html';
    if (window.__domain_name)
        url += '?domain=' + encodeURIComponent (__domain_name);
    var func, parameters, feature;
    if (!!window.ActiveXObject || "ActiveXObject" in window) { // ie
        feature = 'dialogWidth:800px;dialogHeight:520px;status:no;help:no';
        parameters = window;
        window.showModalDialog (url, window, feature);
    } else {
        feature = 'width=800,height=520,menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes';
        window.open (url, null, feature);
    }
}

function _setImage (src, width, height, alt) {
    if (!__holder) return;
    e = document.getElementById (__holder.width);
    e.value = width;
    e = document.getElementById (__holder.height);
    e.value = height;
    e = document.getElementById (__holder.alt);
    e.value = alt;
    var e = document.getElementById (__holder.url);
    e.value = src;
    __holder.contorl.fire ("onchange");
}

function __on_page_loaded () {
    var f = document.forms;
    for (var i = 0; i < f.length; i ++) {
        f [i].onsubmit = __on_form_submit;
    }
}

function __on_form_submit () {
    for (var i = 0 ; i < __rte_editors.length; i ++) {
        var id = __rte_editors [i];
        var textBox = document.getElementById (id);
        var e = CKEDITOR.instances [id];
        if (textBox && e) {
            textBox.value = e.getData ();
        }
    }
    return true;
}